#include "CEGUI/CEGUI.h"
#include "application.h"
Menu::Menu()
{
	mSheet = CEGUI::WindowManager::getSingleton().loadWindowLayout((CEGUI::utf8*)"main_menu.layout");

	CEGUI::Window* w=CEGUI::WindowManager::getSingleton().getWindow("btn_play_game");
	w->subscribeEvent(CEGUI::PushButton::EventClicked,
		              CEGUI::Event::Subscriber(&Menu::OnStartGame, this));

	w=CEGUI::WindowManager::getSingleton().getWindow("btn_credits");
	w->subscribeEvent(CEGUI::PushButton::EventClicked,
		              CEGUI::Event::Subscriber(&Menu::OnCredits, this));

	w=CEGUI::WindowManager::getSingleton().getWindow("btn_highscores");
	w->subscribeEvent(CEGUI::PushButton::EventClicked,
		              CEGUI::Event::Subscriber(&Menu::OnHighscore, this));

	w=CEGUI::WindowManager::getSingleton().getWindow("btn_play_game");
	w->subscribeEvent(CEGUI::PushButton::EventClicked,
		              CEGUI::Event::Subscriber(&Menu::OnStartGame, this));

	w=CEGUI::WindowManager::getSingleton().getWindow("btn_exit");
	w->subscribeEvent(CEGUI::PushButton::EventClicked,
		              CEGUI::Event::Subscriber(&Menu::OnExit, this));


}

Menu::~Menu()
{

}

void Menu::show()
{

	CEGUI::System::getSingleton().setGUISheet(mSheet);
}

bool Menu::OnStartGame(const CEGUI::EventArgs& e)
{
	gApplication->mPlay_GameMenu->show();
	// primjer
	//CEGUI::Window* w=CEGUI::WindowManager::getSingleton().getWindow("play_game");
	//w->setXPosition(CEGUI::UDim(0,0));
	
	return true;
}

bool Menu::OnExit(const CEGUI::EventArgs& e)
{
	gApplication->mExitMenu->show();
	return true;
}

bool Menu::OnCredits(const CEGUI::EventArgs& e)
{
	gApplication->mCreditsMenu->show();
	return true;
}
bool Menu::OnHighscore(const CEGUI::EventArgs& e)
{
	gApplication->mHighscoresMenu->show();
	return true;
}

CreditsMenu::CreditsMenu()
{
	mSheet = CEGUI::WindowManager::getSingleton().loadWindowLayout((CEGUI::utf8*)"credits.layout");
	CEGUI::Window* w=CEGUI::WindowManager::getSingleton().getWindow("credits_back");
	w->subscribeEvent(CEGUI::PushButton::EventClicked,
		              CEGUI::Event::Subscriber(&CreditsMenu::OnBack, this));
}

CreditsMenu::~CreditsMenu()
{

}

HighscoresMenu::HighscoresMenu()
{
	mSheet = CEGUI::WindowManager::getSingleton().loadWindowLayout((CEGUI::utf8*)"highscores.layout");
	CEGUI::Window* w=CEGUI::WindowManager::getSingleton().getWindow("highscores_back");
	w->subscribeEvent(CEGUI::PushButton::EventClicked,
		              CEGUI::Event::Subscriber(&HighscoresMenu::OnBack, this));

}

HighscoresMenu::~HighscoresMenu()
{

}

void HighscoresMenu::show()
{
	CEGUI::System::getSingleton().setGUISheet(mSheet);
}

bool HighscoresMenu::OnBack(const CEGUI::EventArgs& e)
{
	gApplication->mMenu->show();
	// primjer
	//CEGUI::Window* w=CEGUI::WindowManager::getSingleton().getWindow("play_game");
	//w->setXPosition(CEGUI::UDim(0,0));
	return true;
}

void CreditsMenu::show()
{
	CEGUI::System::getSingleton().setGUISheet(mSheet);
}

bool CreditsMenu::OnBack(const CEGUI::EventArgs& e)
{
	gApplication->mMenu->show();
	// primjer
	//CEGUI::Window* w=CEGUI::WindowManager::getSingleton().getWindow("play_game");
	//w->setXPosition(CEGUI::UDim(0,0));
	return true;
}

Play_GameMenu::Play_GameMenu()
{
	mSheet = CEGUI::WindowManager::getSingleton().loadWindowLayout((CEGUI::utf8*)"play_game.layout");
	CEGUI::Window* w=CEGUI::WindowManager::getSingleton().getWindow("play_game_back");
	w->subscribeEvent(CEGUI::PushButton::EventClicked,
		              CEGUI::Event::Subscriber(&Play_GameMenu::OnBack, this));

	w=CEGUI::WindowManager::getSingleton().getWindow("play_game_start");
	w->subscribeEvent(CEGUI::PushButton::EventClicked,
		              CEGUI::Event::Subscriber(&Play_GameMenu::OnStart, this));

}

Play_GameMenu::~Play_GameMenu()
{

}

void Play_GameMenu::show()
{
	CEGUI::System::getSingleton().setGUISheet(mSheet);
}

bool Play_GameMenu::OnBack(const CEGUI::EventArgs& e)
{
	
	gApplication->mMenu->show();
	// primjer
	//CEGUI::Window* w=CEGUI::WindowManager::getSingleton().getWindow("play_game");
	//w->setXPosition(CEGUI::UDim(0,0));
	return true;
}

bool Play_GameMenu::OnStart(const CEGUI::EventArgs& e)
{
	CEGUI::MouseCursor::getSingleton().setVisible(0);
	mSheet->setVisible(0);
	return true;
}


ExitMenu::ExitMenu()
{
	mSheet = CEGUI::WindowManager::getSingleton().loadWindowLayout((CEGUI::utf8*)"in-game.layout");
	CEGUI::Window* w=CEGUI::WindowManager::getSingleton().getWindow("in-game_yes");
	w->subscribeEvent(CEGUI::PushButton::EventClicked,
		              CEGUI::Event::Subscriber(&ExitMenu::OnYes, this));

	w=CEGUI::WindowManager::getSingleton().getWindow("in-game_no");
	w->subscribeEvent(CEGUI::PushButton::EventClicked,
		              CEGUI::Event::Subscriber(&ExitMenu::OnNo, this));

}

ExitMenu::~ExitMenu()
{

}

void ExitMenu::show()
{
	CEGUI::System::getSingleton().setGUISheet(mSheet);
}

bool ExitMenu::OnNo(const CEGUI::EventArgs& e)
{
	gApplication->mMenu->show();
	// primjer
	//CEGUI::Window* w=CEGUI::WindowManager::getSingleton().getWindow("play_game");
	//w->setXPosition(CEGUI::UDim(0,0));
	return true;
}

bool ExitMenu::OnYes(const CEGUI::EventArgs& e)
{
	return true;
}